<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/3/27
 * Time: 10:34
 */
namespace App\Api\Controllers;
use App\Models\ActivityConfig;
use App\Enum\ActivityEnum;
use Illuminate\Http\Request;

class ActivityController extends CommonController
{
    /**
     * @desc 获取活动
     */
    public function index(Request $request)
    {
        $activity_type = $request->input('activity_type');
        $activity_fields = ['id', 'content', 'start_time', 'end_time', 'activity_type', 'created_at', 'updated_at', 'activity_photos', 'last_show_time'];
        $where_arr = [['status', '=', ActivityEnum::ACTIVITY_STATUS_VALID]];
        if($activity_type) {
            $where_arr[] = ['activity_type', '=', $activity_type];
        }

        $activity_list = ActivityConfig::where($where_arr)->get($activity_fields);
        if($activity_list) {
            foreach($activity_list as &$activity) {
                $activity->content = $activity->content ?: null;
                $activity->start_time = time2date($activity->start_time);
                $activity->end_time = time2date($activity->end_time);
                $activity->last_show_time = $activity->last_show_time ? time2date($activity->last_show_time) : null;
                $activity->activity_photos = $activity->activity_photos ? getSignUrl($activity->activity_photos): null;
            }
        }

        return json_success('ok', ['list' => $activity_list]);
    }

    /**
     * @desc 分享活动内容
     */
    public function share_activity_description()
    {
        $activity_data = [
            'title' => '【点击这里，带我一起冲击万元大奖】',
            'description' => '我的影片正在参加微电影人气PK赛，欢迎各路大神围观。帮我点赞助力，共同创作一起拿万元大奖，关注、点赞、转发，大家一起发发发',
        ];
        return json_success('ok', $activity_data);
    }
}